function sendMessage(){

		var nickname = $("#submit_nickname")[0].value;

		var content = $("#submit_content")[0].value;
		
		$.post("chatpost.php",{"name":nickname,"content":content})	
}

function insertNewMessage(messageArray){

	for(var i=0; i<messageArray.length; i++){
		(function(i){
			var userId = messageArray[i]["user_id"];
		
			//创建class为verifyList的tr
			var talkDiv = document.createElement("tr");
			$(talkDiv).attr("class", "verifyList");

			//创建class为speaker_id的td
			var uidTd = document.createElement("td");
			$(uidTd).attr("class", "speakerId");
			$(uidTd).text(messageArray[i]["user_id"]);
			
			//创建class为speaker的td
			var nameTd = document.createElement("td");
			$(nameTd).attr("class", "userName");
			$(nameTd).text(messageArray[i]["user_name"]);

			//在创建一个td
			var stuNumTd = document.createElement("td");
			$(stuNumTd).attr("class", "userStuNum");
			$(stuNumTd).text(messageArray[i]["user_stu_num"]);
			
			//在创建一个td
			var deptTd = document.createElement("td");
			$(deptTd).attr("class", "userDept");
			for (var j = 0; j < messageArray[i]["user_dept"].length; j++) {
				var deptP = document.createElement("p");
				$(deptP).text(messageArray[i]["user_dept"][j]["dept_name"]);
				$(deptTd).append(deptP);
			};

			//还得在创建两个 button 操作用
			var passBu = document.createElement("button");
			$(passBu).attr("class", "userPass");
			$(passBu).text("通过");
			$(passBu).on('click', function(){
				var self = this;
				$.post(passVerifyURL, {user_id:userId}, function(){
					$(self).parents('.verifyList').remove();
				})
			});
			var deleteBu = document.createElement("button");
			$(deleteBu).attr("class", "userDelete");
			$(deleteBu).text("删除");
			$(deleteBu).on('click', function(){
				var self = this;
				$.post(deleteVerifyURL, {user_id:userId}, function(){
					$(self).parents('.verifyList').remove();
				})
			});

			//再搞一个td 装button
			var buttonTd = document.createElement("td");
			$(buttonTd).attr("class", "userDept");
			
			//将子元素放进talkDiv
			$(buttonTd).append(passBu, deleteBu);
			$(talkDiv).append(uidTd, nameTd, stuNumTd, deptTd, buttonTd);
			
			//将talkDiv放在main_content所有子元素的最前面
			$("#qwe").after(talkDiv);
		}(i));
		
	}
}

function getNewMessage(){
	$.get(getUserListURL,function(data){
			insertNewMessage(data);
		});
}

window.onload = function(){
	getNewMessage();
}
